<template>
  <div class="work-order-details-buttons" v-if="details.auditFlag !== 'Y'">
    <!-- TODO 待办结、待终止缺少  -->
    <template v-if="[4, 15].includes(details.status)">
      <el-button type="primary" @click="checkBackDialog.visible = true">核实回访</el-button>
      <el-button type="primary" v-if="details.status === 4" @click="onFinish">确认办结</el-button>
      <el-button type="primary" v-if="details.status === 15" @click="onStop">确认终止</el-button>
      <el-button type="primary" plain @click="backDialog.visible = true">退回重办</el-button>
      <el-button type="primary" plain @click="acceptAndTransferDialog.visible = true">转其他部门重办</el-button>
    </template>

    <!-- TODO 已办结、已终止 -->
    <template v-if="[5, 8].includes(Number(details.status))">
      <el-button type="primary" @click="onCheckStop">结案回访</el-button>
      <el-button type="primary" plain @click="onModifyStatus">修改结案状态</el-button>
    </template>
    <!-- 办结 -->
    <finallyDialog :visible.sync="finallyDialog.visible" :workOrderNo="details.workOrderNo" :status="finallyDialog.status" @success="rePlayLoadData"></finallyDialog>
    <!-- 退回 -->
    <backDialog :visible.sync="backDialog.visible" :workOrderNo="details.workOrderNo" @success="rePlayLoadData"></backDialog>
    <!-- 核实回访 -->
    <checkBackDialog :visible.sync="checkBackDialog.visible" :workOrderNo="details.workOrderNo" :workOrderId="details.id" @success="rePlayLoadData"></checkBackDialog>
    <!-- 受理案件/转向其他部门-->
    <acceptAndTransferDialog :visible.sync="acceptAndTransferDialog.visible" :workOrderNo="details.workOrderNo" @success="rePlayLoadData"></acceptAndTransferDialog>
    <!-- 修改结案状态 -->
    <modify-finish-status :visible.sync="modifyFinishStatus.visible" :workOrderNo="details.workOrderNo" :finishStatus="details.finishStatus" @success="rePlayLoadData"></modify-finish-status>
  </div>
</template>

<script>
import backDialog from "@/views/workOrder/components/backDialog.vue";
import checkBackDialog from "@/views/workOrder/components/checkBackDialog.vue";
import finallyDialog from "@/views/workOrder/components/finallyDialog.vue";
import acceptAndTransferDialog from "@/views/workOrder/components/acceptAndTransferDialog.vue";
import { rolePermissionsMixin } from "@/views/workOrder/mixin";
import detailsButtonMixin from "@/views/workOrder/components/detailsButtonMixin";
import ModifyFinishStatus from "./ModifyFinishStatus.vue";

export default {
  name: "FinishButton",
  mixins: [detailsButtonMixin, rolePermissionsMixin],
  components: {
    backDialog,
    checkBackDialog,
    finallyDialog,
    acceptAndTransferDialog,
    ModifyFinishStatus,
  },
  data() {
    return {
      finallyDialog: { visible: false, status: 1 },
      backDialog: { visible: false },
      checkBackDialog: { visible: false },
      acceptAndTransferDialog: { visible: false },
      modifyFinishStatus: { visible: false },
    };
  },
  methods: {
    onStop() {
      this.finallyDialog.status = 2;
      this.finallyDialog.visible = true;
    },
    onFinish() {
      this.finallyDialog.status = 1;
      this.finallyDialog.visible = true;
    },
    onCheckStop() {
      this.finallyDialog.status = 3;
      this.finallyDialog.visible = true;
    },
    onModifyStatus() {
      this.modifyFinishStatus.visible = true;
    },
  },
};
</script>

<style lang="less" scoped>
.work-order-details-buttons {
  margin-right: 10px;
}
</style>
